using FluentNHibernate.Mapping;

namespace Rhinestone.Domain.Mappings
{
    /// <summary>
    /// Defines mapping for the <see cref="WorkItem"/> entity.
    /// </summary>
    public class WorkItemMap : ClassMap<WorkItem>
    {
        public WorkItemMap()
        {
            WithTable("WorkItems");

            Id(prop => prop.WorkItemID)
                    .Access.AsReadOnlyPropertyThroughCamelCaseField()
                    .GeneratedBy.Identity();

            References(prop => prop.Project);

            Map(prop => prop.Title);

            Map(prop => prop.Description);

            Map(prop => prop.Created)
                    .Access.AsReadOnlyPropertyThroughCamelCaseField();

            Map(prop => prop.Modified)
                    .Access.AsReadOnlyPropertyThroughCamelCaseField();

            Map(prop => prop.Status);

            Map(prop => prop.Priority);

            Map(prop => prop.CreatedBy)
                    .Access.AsReadOnlyPropertyThroughCamelCaseField()
                    .TheColumnNameIs("CreatedByUsername")
                    .CustomTypeIs(typeof (RhinestoneUserType));

            Map(prop => prop.AssignedTo)
                    .Access.AsReadOnlyPropertyThroughCamelCaseField()
                    .TheColumnNameIs("AssignedToUsername")
                    .CustomTypeIs(typeof (RhinestoneUserType));

            HasMany(prop => prop.Attachments)
                    .Access.AsReadOnlyPropertyThroughCamelCaseField();

            HasMany(prop => prop.RelatedWorkItems)
                    .Access.AsReadOnlyPropertyThroughCamelCaseField();

        }
    }
}